#include "loggermanger.h"

namespace vlog
{

LoggerManger::LoggerManger() : m_root(std::make_shared<Logger>("root"))
{
    m_root->AddLogAppender(std::make_shared<StdOutLogAppender>());
    m_loggers.insert(std::make_pair(m_root->GetLogName(), m_root));
}

Logger::ptr LoggerManger::GetLogger(const std::string_view name) noexcept
{
    auto it = m_loggers.find(std::string(name));
    if (m_loggers.end() != it)
    {
        return it->second;
    }

    Logger::ptr logger = std::make_shared<Logger>(name);
    m_loggers.insert(std::make_pair(name, logger));
    return logger;
}

} // namespace vlog
